// 获取数据
function getchatgpt(params) {
  return new Promise((ress,rej)=>{
    wx.request({
        url: "https://hk.wxnodes.cn/wxCo.php", //
        data: {
          q:params,
        }, 
        timeout:1000000,
        method:'GET',
        header: {
          'content-type': 'application/json' // 默认值
        },
        success (res) {
          console.log(res)
          wx.hideLoading();
          ress(res)
        },
        fail(err){
          wx.showToast({
            title: '网络错误...',
            icon:'error',
            duration:2000
          })
          rej(err)
        },
      })
    })
}

// 转语音
function getsounds(meg,token) {  
  wx.request({
      method: 'POST',
      url:'https://tsn.baidu.com/text2audio',
      headers: {
              'Content-Type': 'application/x-www-form-urlencoded',
              'Accept': '*/*'
      },
      data:{
        tex:encodeURI(meg),
        tok:token,
        cuid: '45435u65fdsahgwfer23',
        ctp: '1',
        lan: 'zh'
      },
        success (res) {
          console.log(res)
        },
        fail(err){
        },
      })
}


function getAccessToken() {
const AK = "988294HyU13GMBVlqRpdfy7p"
const SK = "Fvrxu6u6FTN8aoBgbHmOXMErTrR1ACoS"
  return new Promise((resolve, reject) => {
    wx.request({
      method:'POST',
      url:'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=' + AK + '&client_secret=' + SK,
      success(res){
        console.log(res)
        resolve(res)
      },
      fail(err){
        reject(err)
      }
    })
  })
}

module.exports={
  getchatgpt,getsounds,getAccessToken
}